//
//  TopView.swift
//  QQZone
//
//  Created by xmg on 16/9/1.
//  Copyright © 2016年 wlis. All rights reserved.
//

import UIKit

private let kIconTitleH : CGFloat = 30
class TopView: UIButton {

    var isBool : Bool = false
    

}

extension TopView{

    /** 监听屏幕方向改变,设置frame */
    func setUpScreenDirection(isBool :Bool){
        /** 屏幕方向 */
        self.isBool = isBool
        /** 设置frame */
        let dockW = superview?.frame.width
        let w = isBool ? dockW! / 3 : (dockW! - 10)
        let h = isBool ? (w + kIconTitleH) : w
        let x : CGFloat = (dockW! - w) * 0.5
        let y : CGFloat = 60
        
        frame = CGRect(x: x, y: y, width: w, height: h)
        
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        if isBool{
        
            imageView?.frame = CGRect(x: 0, y: 0, width: frame.width, height: frame.width)
            titleLabel?.frame = CGRect(x: 0, y: frame.width, width: frame.width, height: kIconTitleH)
        }else{
        
            imageView?.frame = bounds
            titleLabel?.frame = CGRectZero
        }
    }
}